package ua.org.nuos.sdms.clientgui.client.controller;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: dio
 * Date: 19.02.12
 * Time: 16:38
 * To change this template use File | Settings | File Templates.
 */
public class ControllerLocator {
    private Map<String, AbstractController> controllers;

    public void registerController(AbstractController controller) {
        if (controllers == null) {
            controllers = new HashMap<String, AbstractController>();
        }
        controllers.put(controller.getId(), controller);
    }

    public void unregisterController(String id) {
        if (controllers != null) {
            controllers.remove(id);
        }

    }

    public AbstractController getController(String id) {
        if (!controllers.containsKey(id)) {
            throw new RuntimeException("No such blackboard " + id);
        }
        return controllers.get(id);
    }

    public void resetData() {
        controllers = null;
    }
}
